package android.FiltrosJava;

import java.awt.image.BufferedImage;
import java.awt.image.WritableRaster;

public class Mosaic extends AbstractImageBasic {
	protected int window = 10;
	public Mosaic(int mosaicSize){
		window = mosaicSize;
		if (window < 1)
			window = 2;		
	}
	
    public BufferedImage applyFilter(BufferedImage dst){
    			
		int dimX = dst.getWidth();
		int dimY = dst.getHeight();
		int x, y, px, py, px1, py1;		
    	WritableRaster raster_dst = dst.getRaster();
    	int[] imageData = new int[raster_dst.getNumBands()];    	
    	
    	y = 0;
    	while (y < dimY){
    		x = 0;
    		while (x < dimX){
    			px1 = (int) (x + Math.random() * (window - 1));
    			py1 = (int) (y + Math.random() * (window - 1));
    			if (px1 >= dimX)
    				px1 = dimX - 1;
    			
    			if (py1 >= dimY)
    				py1 = dimY - 1;
    			
    			raster_dst.getPixel(px1,py1,imageData);
    			
    			py = y;
    			while ((py < y + window) && (py < dimY)){
    				px = x;
    				while ((px < x + window) && (px < dimX)){
    					raster_dst.setPixel(px,py,imageData);
    					px++;
    				}    	
    				py++;
    			}
    			x += window;
    		}
    		y += window;
    	}
		
		return dst;	
    }
}